import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import {Backend} from '../../providers/backend';

import {Information} from './tab-my-information';
import { Events } from 'ionic-angular';
import {Meetingpayment} from '../tab-events/tab-meeting-payment';
@Component({
  templateUrl: 'build/pages/tab-my/tab-my-conference.html'
})
export class Conference {

  static get parameters() {
    return [[NavController], [NavParams], [Backend], [Events]];
  }

  constructor(nav, params, backend,events) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.events = events;
    this.uid;
    this.rmb=[];
    this.price=[];
    this.meet_stat=[];
    this.email = params.get('email');
    this.events.subscribe('user:createdd', (userEventData) => {
      // userEventData is an array of parameters, so grab our first and only arg
      console.log(userEventData);
      
      this.backend.isLogined()
        .then(result => {
          this.result = result;
          console.log(this.result);
          this.email = this.result.email;
          this.uid = this.result.uid;
          this.backend.conference(this.uid)
            .then(result => {
              this.conference = result.data;

              for (let i = 0; i < this.conference.length; i++) {
                this.mid = this.conference[i].mid;
                this.backend.meetingdetails(this.mid)
                  .then(result => {
                    
                    this.rmb[i] = result.result[0].payinfo.rmb;
                    this.price[i] = result.result[0].payinfo.price;
                    this.meet_stat[i] = result.result[0].meet_stat;
                  });

              }
              console.log(this.rmb);
            });
        });
    });
    this.backend.isLogined()
      .then(result => {
        this.result = result;
        console.log(this.result);
        this.email = this.result.email;
        this.uid = this.result.uid;
        this.backend.conference(this.uid)
          .then(result => {
            this.conference = result.data;
            
            for(let i =0;i<this.conference.length;i++){
              this.mid=this.conference[i].mid;
              this.backend.meetingdetails(this.mid)
          .then(result => {
            
            this.rmb[i]=result.result[0].payinfo.rmb;
            this.price[i]=result.result[0].payinfo.price;
            this.meet_stat[i]=result.result[0].meet_stat;
          });
              
            }
            console.log(this.rmb);
          });
      });
    this.conference;
    this.contents = params.get('contents');

  }
  edit() {
    this.nav.push(Information, { email: this.email, uid: this.uid });
  }

  /**
 * 下拉刷新
 */
  // doRefresh(refresher) {
  //   this.start = 0;
  //   console.log('Begin async operation', refresher);
  //   this.select_menu;
  //   this.backend.conference()
  //     .then(result => {
  //       this.conference = result;
  //     });
  //   setTimeout(() => {
  //     console.log('Async operation has ended');
  //     refresher.complete();
  //   }, 2000);
  // }

  /**
   * 取消订单
   */
  cancel(uid, id) {
    console.log(uid, id);
    this.backend.cancel(uid, id)
      .then(result => {
        if (result.status == 1) {
          console.log('成功');
          this.events.publish('user:createdd', 1);
        }
      });
  }
  topay(rmb,price){
this.nav.push(Meetingpayment,{'price':price,'rmb':rmb});
  }
}
